package com.zhuiyun.project.api.dict.controller;

import com.zhuiyun.project.api.dict.entity.DictData;
import com.zhuiyun.project.api.dict.model.DictDataModel;
import com.zhuiyun.project.api.dict.model.DictTypeModel;
import com.zhuiyun.project.api.dict.service.impl.DictDataServiceImpl;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DictDataController
 * @Description TODO
 * @Author Root
 * @Date 2023/6/23 9:21
 **/
@RestController
@Api(tags = "字典数据管理")
@RequestMapping("/dictData")
@Slf4j
@CrossOrigin
public class DictDataController {
    @Autowired
    DictDataServiceImpl dictDataService;

    /**
     * @Author 小江
     * @Description //TODO 查询类型
     * @Date 8:40 2023/7/7
     **/
    @GetMapping("/selectDict")
    CommonResult selectDict(DictDataModel dictDataModel) {
        return dictDataService.selectDict(dictDataModel);
    }

    /**
     * @param pageRequest
     * @param dictId
     * @Author Root
     * @Description 分页查询
     * @Date 2023/7/24 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectDataByPage")
    public CommonResult selectDataByPage(PageRequest pageRequest, Integer dictId) {
        return dictDataService.selectById(pageRequest, dictId);
    }

    /**
     * @param dictDataModel
     * @Author Root
     * @Description 添加字典信息
     * @Date 2023/7/24 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/insertDictData")
    public CommonResult insertDictData(DictDataModel dictDataModel) throws CommonException {
        return dictDataService.insertDictData(dictDataModel);
    }

    /**
     * @param dictDataModel
     * @Author Root
     * @Description 修改字典信息
     * @Date 2023/7/24 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/updateDictData")
    public CommonResult updateDictData(DictDataModel dictDataModel) {
        return dictDataService.updateDictData(dictDataModel);
    }

    /**
     * @Author Root
     * @Description 删除字典信息
     * @Date 2023/7/24 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param dataId
     */
    @DeleteMapping("/deleteByDataId")
    public CommonResult deleteDictData(Integer dataId) throws CommonException {
        return dictDataService.deleteDictData(dataId);
    }

    /**
     * @param dictLabel
     * @Author Root
     * @Description 模糊查询
     * @Date 2023/7/24 19:31
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectLike")
    public CommonResult selectLike(String dictLabel) {
        return dictDataService.selectLike(dictLabel);
    }

    /**
     * 查询
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/7/14 10:59
     * @parameter []
     */
    @GetMapping("/selectOne")
    public CommonResult selectOneById() {
        List<DictData> dictData = dictDataService.selectOneById();
        return CommonResult.ok(dictData);
    }
}
